<%--
  作者:张伟

  联系:adamzzww@163.com
  时间:2016-11-30
  说明:无
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>编辑菜单信息</title>
    <%@include file="../../desktop/include/assets.jsp" %>
    <%
        String url = request.getContextPath() + Global.PATH;
    %>

    <style>
        .infoForm {
            padding: 20px
        }
    </style>
</head>
<body>
<div class="infoForm">
    <form id="editForm" name="editForm" class="form-horizontal form-condensed" role="form" method="post"
          action="<%=url%>/menu">
        <div class="form-group">
            <label class="col-xs-3 control-label" for="menuName">菜单名称</label>
            <div class="col-xs-6">
                <input type="text" name="menuName" id="menuName" value="${menuEntity.menuName}" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-3 control-label" for="menuUrl">菜单资源路径</label>
            <div class="col-xs-6">
                <input type="text" name="menuUrl" id="menuUrl" value="${menuEntity.menuUrl}" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-3 control-label">上级菜单</label>
            <div class="col-xs-6">
                <select name="pMenuId" id="pMenuId" class="form-control">
                    <c:if test="${!empty menuList }">
                        <option value="0" <c:if test="${0 == menuEntity.pMenuId }">selected="selected"</c:if>></option>
                        <c:forEach items="${menuList }" var="menu">
                            <option value="${menu.menuId}" ${menuEntity.pMenuId == menu.menuId ?"selected":""} >${menu.menuName}</option>
                        </c:forEach>
                    </c:if>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-3 control-label">菜单排序</label>
            <div class="col-xs-6">
                <input type="text" name="menuOrder" id="menuOrder" value="${menuEntity.menuOrder}" class="form-control">
            </div>
        </div>
        <hr/>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" id="saveBtn" class="btn btn-primary" value="保存" data-loading="稍候...">
                <c:if test="${!empty menuEntity.menuId }">
                    <input type="hidden" name="menuId" value="${menuEntity.menuId}">
                </c:if>
            </div>
        </div>
    </form>
</div>

<script>

    $(function () {
        var validate = $("#editForm").validate({
            //debug: true, //调试模式取消submit的默认提交功能
            rules: {
                menuName: {
                    required: true
                }
            },
            messages: {
                menuName: {
                    required: "请输入菜单名称"
                }
            },
            submitHandler: function (form) {   //表单提交句柄,为一回调函数，带一个参数：form
                $.ajax({
                    url: form.action,
                    type: form.method,
                    data: $(form).serialize(),
                    success: function (data) {
                        // 提交表单
                        if (data == "success") {
                            alert("提交成功！");
                            //$("#editForm")[0].reset();
                            window.parent.location.reload();
                        } else {
                            alert("提交失败！");
                        }
                    }
                });
            },
        });
    });
</script>

</body>
</html>
